<template>
	<view>
		<!-- logo -->
		<view class="logo">
			<view >
				<image src= '../../static/image/03.jpg' style="border-bottom: 4px solid whitesmoke;">
			</view>
			<view>Hello!</view>
			<view>登陆你的账号</view>
		</view>
		
		<!-- 登录表单 -->
		<view class="formLogin">
			<view>
				<input type="text" placeholder="请输入账号" v-model="userName"/>
			</view>
			<view>
				<input type="password" placeholder="请输入密码" v-model="userPwd"/>
			</view>
			<view>忘记密码?</view>
			<view>
				<button class="login" @click="login">登录</button>
			</view>
		</view>
		
		<!-- 注册链接 -->
		<view style="display: flex;justify-content: center;">
			没有账号？<text style=" border-bottom: 1px solid #90A672;color: #90A672;" @click="regist">立即注册</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userName:"",
				userPwd:"",
				userId:0,
			}
		},
		methods: {
			regist(){
				uni.navigateTo({
					url:'/pages/register2/register2'
				})
			},
			login:function() {
				var that = this;
				
				uni.request({
					url: 'http://localhost:8888/login',
					method: 'GET',
					data:{
						userName:this.userName,
						userPwd: this.userPwd,	
					},
					success(res) {
						if(res.data.code == 0){
							that.userAvatar = res.data.data[0].userAvatar
							console.log(res.data.data[0].userId)
							console.log(res)
							if(res.data.data[0].userName == 'admin' && res.data.data[0].userPwd == '123456'){
								uni.reLaunch({
									url:'/pages/addQuestion/addQuestion'
								});	
							}else{
								uni.reLaunch({
									url:'/pages/index/index'
							});	
							}
							uni.setStorageSync('userName',that.userName)
							uni.setStorageSync('userAvatar',that.userAvatar)
							
						}else{
							uni.showToast({
								title:"登录失败",
								icon:"error"
							})
						}	
					} 
			
				});	

		
			},
	 	}
	}
</script>

<style>
	/* logo */
	.logo {
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.logo image {
		width: 750rpx;
		height: 300rpx;
	}
	.logo >view:nth-child(2) {
		font-family: 隶书;
		font-size: 60rpx;
		font-weight: bold;
		padding-top: 20rpx;
	}
	.logo >view:nth-child(3) {
		color: #90A672;
		padding-top: 20rpx;
	}
	/* 登录验证表单 */
	.formLogin {
		margin-top: 40rpx;
	}
	.formLogin >view {
		display: flex;
		padding: 40rpx;
	}

	.formLogin input {
		
		margin-left: 20%;
		width: 60%;
		border-bottom: 2px solid #90A672;
	}
	.formLogin >view:nth-child(3) {
		display: flex;
		flex-direction: row-reverse;
	}
	.formLogin >view:nth-child(4) button {
		width: 60%;
		border-radius:20rpx ;
		color: white;
		background-color: #90A672;
	}
</style>